package edu.predatorwars.client.visualization;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Mesh;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.Pixmap.Format;
import com.badlogic.gdx.graphics.Texture.TextureFilter;
import com.badlogic.gdx.graphics.Texture.TextureWrap;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g3d.loaders.obj.ObjLoader;
import com.badlogic.gdx.graphics.glutils.ShaderProgram;


public class SharedVisResources {
	
	public static final String resource_root_directory = "resources/client/visualization/";
	
	public static Mesh gorilla, bear, elephant, wolf, snake;
	public static BitmapFont font_small, font_large;
	public static ShaderProgram toonShader;
	public static Texture toon;
	
	public static void init() {
		gorilla = ObjLoader.loadObj(Gdx.files.internal(resource_root_directory + "models/gorilla.obj").read());
		wolf = ObjLoader.loadObj(Gdx.files.internal(resource_root_directory + "models/wolf.obj").read());
		bear = ObjLoader.loadObj(Gdx.files.internal(resource_root_directory + "models/bear.obj").read());
		elephant = ObjLoader.loadObj(Gdx.files.internal(resource_root_directory + "models/elephant.obj").read());
		snake = ObjLoader.loadObj(Gdx.files.internal(resource_root_directory + "models/snake.obj").read());
		font_small = new BitmapFont();
		font_small.scale(0.0525f);
		font_small.getRegion().getTexture().setFilter(TextureFilter.Linear, TextureFilter.MipMapLinearLinear);
		font_large = new BitmapFont(Gdx.files.internal(resource_root_directory + "fonts/verdana39.fnt"),Gdx.files.internal(resource_root_directory + "fonts/verdana39.png"),false);
		font_large.getRegion().getTexture().setFilter(TextureFilter.Linear, TextureFilter.Linear);
		font_large.scale(-0.4f);
		font_large.setUseIntegerPositions(true);
		toonShader = new ShaderProgram(Gdx.files.internal(resource_root_directory + "shaders/ModelToonShader-Vert.glsl").readString(), Gdx.files.internal(resource_root_directory + "shaders/ModelToonShader-Frag.glsl").readString());
		toon =  new Texture(Gdx.files.internal(resource_root_directory + "textures/toon_outline.jpg"), Format.RGBA8888, true);
		
		toon.setFilter(TextureFilter.MipMapLinearLinear, TextureFilter.Linear);
		toon.setWrap(TextureWrap.ClampToEdge, TextureWrap.ClampToEdge);
		
		
		
		float[] light0 = {-100,0,0,1};
		float[] light1 = {100,-100,0,1};
		float[] light2 = {0,0,100,1};
		toonShader.begin();
		toonShader.setUniformf("light0", light0[0], light0[1], light0[2], light0[3]);
		toonShader.setUniformf("light1", light1[0], light1[1], light1[2], light1[3]);
		toonShader.setUniformf("light1", light2[0], light2[1], light2[2], light0[2]);
		toonShader.end();
	}
	
	public static void dispose() {
		gorilla.dispose();
		bear.dispose();
		elephant.dispose();
		wolf.dispose();
		snake.dispose();
		font_small.dispose();
		font_large.dispose();
		toonShader.dispose();
		toon.dispose();
		
	}
}